package com.itheima;
import java.util.HashMap;
import java.util.Map;
/**
 * @ProjectName: ybxy6
 * @Titile: MapPractice
 * @Author: Chilemey
 * @Description: TODO
 */
public class MapPractice {
    public static void main(String[] args) {
        Map<String,String> data = new HashMap<>();
        data.put("张三","A");
        data.put("李四","B");
        data.put("王五","C");
        data.put("赵六","C");
        data.put("赵六","B");
        data.put("小王1" , "A");
        data.put("小王2" , "B");
        data.put("小王3" , "C");
        data.put("小王4" , "A");
        data.put("小王5" , "C");
        data.put("小王6" , "B");
        data.put("小李1" , "A");
        data.put("小李2" , "B");
        data.put("小李3" , "C");
        data.put("小李4" , "A");
        data.put("小李5" , "C");
        data.put("小李6" , "A");
        count(data);

    }
    public static void count (Map<String,String> data){
        //创建一个新的map集合
        //遍历data集合
        Map<String,Integer> resultMap = new HashMap<>();
        data.forEach((key,value)->{
            boolean containsKey = resultMap.containsKey(value);
            if (containsKey){
                //将老的值取出来+1,重新存入
                Integer oldCount = resultMap.get(value);
                resultMap.put(value,oldCount+1);
            }
            else {
                resultMap.put(value,1);
            }
        });

        resultMap.forEach((key,value)->{
            System.out.println(key+"="+value);
        });
    }

}